import 'package:flutter/material.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/entrys/rp/inv_list_entity.dart';
import 'package:xiongan_app_yy/net/internet_api.dart';
import 'package:xiongan_app_yy/pages/common/LoadBuilder.dart';
import 'package:xiongan_app_yy/utils/toast_utils.dart';
import 'package:xiongan_app_yy/widgets/in_task_list_widget.dart';
import 'package:xiongan_app_yy/widgets/search_widget.dart';

class OutTaskSearch extends StatefulWidget {
  @override
  _OutTaskSearchState createState() => _OutTaskSearchState();
}

class _OutTaskSearchState extends State<OutTaskSearch> {
  int size = 0;
  InvListEntity invListEntity;

  @override
  Widget build(BuildContext context) {
    return SearchWidget(
      tipsText: "请输入出库任务单号",
      onTapFuns: (value) {
        if (value != null && value
            .toString()
            .length > 0) {
          onSearch(value);
        } else {
          TostUtil.showToast("请输入出库任务单号");
        }
      },
      child: LoadBuilder(
        visibility: false,
        emptyVisibility: size == 0,
        emptyTextVisibility: size == 0,
        textEmptyTips: "暂无内容",
        builder: ListView.separated(
            itemBuilder: (BuildContext context, int index) {
              InvListData data = invListEntity.datas.elementAt(index);
              return InTaskListWidget<InvListData>(
                context: context,
                index: index,
                data: data,
                type: "出库任务",
              );
            },
            separatorBuilder: (BuildContext context, int index) =>
                Divider(height: 1, color: Colors.transparent),
            itemCount: size),
      ),
    );
  }

  void onSearch(value) {
    InternetAPI.getInstance()
        .get("OMS/MiWarehouseOutTask/GetAllMiWarehouseOutTask", (data) {
      setState(() {
        invListEntity = InvListEntity.fromJson(data);
        size = invListEntity.datas.length;
      });
    }, params: {
      'operaterUserId': DataSingleton().Data.id,
      'userId': DataSingleton().Data.id,
      'tenantId': DataSingleton().Data.tenantId,
      'pageNo': -1,
      'taskno': value,
    });
  }
}
